package com.adcc.automation.config;


import com.adcc.automation.service.transfer.ActiveMqFactory;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.util.Map;

@Data
public class YmlConfig {
    private static final Logger logger = LoggerFactory.getLogger(YmlConfig.class);
    private int reply_switch = 0;
    
    private static final YmlConfig instance = new YmlConfig();

    public static synchronized YmlConfig getInstance() {
        return instance;
    }
    
    public void init(){
        //读取配置文件
        try {
            Yaml yaml = new Yaml();
            File configFile = new File("./config/application.yml");
            Map<String, Object> config = yaml.load(new FileInputStream(configFile));
            this.reply_switch = (int) config.get("reply_switch");
            logger.info("reply_switch: {}", this.reply_switch);
        } catch (Exception e) {
           logger.error("YmlConfig init error {}", e.getMessage());
           throw new RuntimeException(e);
        }
    }
}
